package com.iotechn.unimall.app.api.active;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.iotechn.unimall.core.exception.ServiceException;
import com.iotechn.unimall.data.domain.ActiveInfoDO;
import com.iotechn.unimall.data.mapper.ActiveInfoMapper;
import com.iotechn.unimall.data.model.Page;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ActiveInfoServiceImpl implements ActiveInfoService {
    @Autowired
    private ActiveInfoMapper activeInfoMapper;

    @Override
    public Page<ActiveInfoDO> list(Integer page, Integer limit) throws ServiceException {
        Wrapper<ActiveInfoDO> wrapper = new EntityWrapper<ActiveInfoDO>();
        /**if (!StringUtils.isEmpty(name)) {
         wrapper.like("username", name);
         }**/
        wrapper.orderBy("id", false);
        Integer count = activeInfoMapper.selectCount(wrapper);
        List<ActiveInfoDO> ActiveInfoDOS = activeInfoMapper.selectPage(new RowBounds((page - 1) * limit, limit), wrapper);
        return new Page<>(ActiveInfoDOS, page, limit, count);
    }

    @Override
    public ActiveInfoDO detail(Long id) throws ServiceException {
        return activeInfoMapper.selectById(id);
    }


}